package domain;

import java.util.ArrayList;

public class PreferenceManager {
	
	private StorageNode m_StorageNode;
	private StackHolder m_Recipient;
	private StackHolder m_Sender;
	private ArrayList<Node> m_BackUpNodes;
	
	public PreferenceManager() {}
	
	public PreferenceManager(StorageNode storageServer, StackHolder recipient, StackHolder sender, ArrayList<Node> backupNodes) {
		m_StorageNode = storageServer;
		m_Recipient = recipient;
		m_Sender = sender;
		m_BackUpNodes = backupNodes;
	}
	
	public void connectBackupNodes() {
		
		// Create mountpoint for backupNode.
		if (m_BackUpNodes != null && m_BackUpNodes.size() > 0) {
		
			for (Node node : m_BackUpNodes) {
				
				for (Share share : node.getShares()) {
					share.mountShare(m_StorageNode.getBackupsMountPoint(), node.getName());
				}
			}
		}
	}

	public StackHolder getRecipient() {
		return m_Recipient;
	}

	public StackHolder getSender() {
		return m_Sender;
	}

	public StorageNode getStorageServer() {
		return m_StorageNode;
	}
	
	public ArrayList<Node> getBackupNodes() {
		return m_BackUpNodes;
	}
	
	public double getAvailableMemory() {
		double availabeMemory = 0;
		
		for (Node node : m_BackUpNodes) {
			for (Share share : node.getShares()) {
				availabeMemory += share.getAvailableMemoryAsDouble();
			}
		}
		
		return availabeMemory;
	}
}
